<?php
namespace app\admin\controller;
use think\Controller;
use think\Session;
use app\admin\model\Users;

class login extends Controller
{
  public function index(){
  	return view('login');
  }

  public function login(){
  	$post = input('post.');

  	$captcha = $post["captcha"];
  	$username = $post['username'];
  	$password = md5($post['password']);

  	if(!captcha_check($captcha)){
 		//验证失败
 		$this->error('验证码错误！');
 	}else{

 		$user=Users::get(['username'=>$username,'password'=>$password]);
 		if ($user) {
 			Session::set('username',$user->username);
 			//$this->success('登录成功！');
 			$this->redirect('./admin/index');
 		} else {
 			$this->error('用户登录失败！');
 		}
 		
 		//exit(md5('admin').'验证码正确！');
 		
 	}

}

	public function logout(){

 		Session::clear();
 		$this->success('退出成功！','./admin/login');
 	}

  public function register(){
  	return view();
  }

}
